import { ajaxAsync, getUrlParamByKey } from 'vue-xiaobu-utils'
import { OrderDetailModel } from '../models/OrderDetailModel'

async function getOrderDetail() {
  let sessionID = localStorage.getItem('XIAOBUSESSION')
  let orderID = getUrlParamByKey('ORDER_NO')
  let postData = {
    SESSION_ID: sessionID,
    ORDER_ID: orderID
  }
  let res
  res = await ajaxAsync('/order/query2', postData)
  let body = new OrderDetailModel(
    res.ORDER_ID,
    res.OUT_ORDER_NO,
    res.ORDER_STATE,
    res.PAY_FEE,
    res.OP,
    res.STORE_ORDER[0].STORE_NAME,
    res.STORE_ORDER[0].SKU_LIST[0].SKU_NAME,
    res.STORE_ORDER[0].SKU_LIST[0].SKU_NUM,
    res.STORE_ORDER[0].SKU_LIST[0].SKU_PIC,
    res.PAYMENT,
    res.PAYMENT_NAME,
    res.PAYMENT_TIME,
    res.CREATE_TIME
  )
  return body
}

export { getOrderDetail }
